<div id="particleFactoryTestPhysicalSimulationB" style="font-size:30px; position: absolute; left: 100px; top:250px; width:30px; height:30px;">B</div>
<div id="particleFactoryTestPhysicalSimulationO" style="font-size:30px; position: absolute; left: 100px; top:220px; width:30px; height:30px;">o</div>
<div id="particleFactoryTestPhysicalSimulationU" style="font-size:30px; position: absolute; left: 100px; top:190px; width:30px; height:30px;">u</div>
<div id="particleFactoryTestPhysicalSimulationN" style="font-size:30px; position: absolute; left: 100px; top:160px; width:30px; height:30px;">n</div>
<div id="particleFactoryTestPhysicalSimulationC" style="font-size:30px; position: absolute; left: 100px; top:130px; width:30px; height:30px;">c</div>
<div id="particleFactoryTestPhysicalSimulationE" style="font-size:30px; position: absolute; left: 100px; top:100px; width:30px; height:30px;">e</div>

<div id="particleFactoryTestPhysicalSimulationFloor" style="position: absolute; left:1px; top:400px; width:1000px; height:10px; background-color:#333333;"> </div>
<div id="particleFactoryTestPhysicalSimulationWall" style="position: absolute; left:0px; top:0px; width:400px; height:10px; background-color:#333333;"> </div>

<div id="particleFactoryTestTestconsole" style="position: absolute; left: 50px; top:350px;"></div>

<button id="particleFactoryTestPhysicalSimulationRestart" >Start over</button>
<script type="text/javascript">
var particleFactoryTestPhysicalSimulation = new physHtml.main("particleFactoryTestPhysicalSimulation");

function particleFactoryTest()
{
  particleFactoryTestPhysicalSimulation.initialize();  
  particleFactoryTestPhysicalSimulation.maxTime = 20000;
  particleFactoryTestPhysicalSimulation.console = document.getElementById("particleFactoryTestTestconsole");

  particleFactoryTestIds = new Array();
  particleFactoryTestIds.push("particleFactoryTestPhysicalSimulationB");
  particleFactoryTestIds.push("particleFactoryTestPhysicalSimulationO");
  particleFactoryTestIds.push("particleFactoryTestPhysicalSimulationU");
  particleFactoryTestIds.push("particleFactoryTestPhysicalSimulationN");
  particleFactoryTestIds.push("particleFactoryTestPhysicalSimulationC");
  particleFactoryTestIds.push("particleFactoryTestPhysicalSimulationE");

  particleFactoryTestFactory = new physHtml.particleFactory(particleFactoryTestPhysicalSimulation);
  particleFactoryTestFactory.gravity = $V([0.0, 10 * 9.8]);
  particleFactoryTestFactory.offset = $V([-0.5, -0.5]);
  particleFactoryTestFactory.rotationOffset = $V([0.0, 0.0]);
  particleFactoryTestObjects = particleFactoryTestFactory.createOrGetObjects(particleFactoryTestIds);

  var floor = new physHtml.wall( $V([1, 400]), 0.0, 1000, 10, 0.8 );
  var wall = new physHtml.wall($V([200, 200]), -90.0, 400, 10, 0.8);

  for (var i = 0; i < particleFactoryTestObjects.length; i++){
    particleFactoryTestObjects[i].connect(floor, floor);
    particleFactoryTestObjects[i].connect(wall, wall);
    particleFactoryTestObjects[i].velocity = $V([5 * (10 - i), -100.0]);
  }

  var floorObjectHTML = new physHtml.htmlObject(document.getElementById('particleFactoryTestPhysicalSimulationFloor'), floor);
  var wallObjectHTML = new physHtml.htmlObject(document.getElementById('particleFactoryTestPhysicalSimulationWall'), wall);
  particleFactoryTestPhysicalSimulation.htmlObjects.addObject( floorObjectHTML );
  particleFactoryTestPhysicalSimulation.htmlObjects.addObject( wallObjectHTML );

  document.getElementById('particleFactoryTestPhysicalSimulationRestart').addEventListener('click', function() {
    for (var i = 0; i < particleFactoryTestObjects.length; i++){
      particleFactoryTestObjects[i].position = $V([100, 250 - 30 * i]);
      particleFactoryTestObjects[i].velocity = $V([5 * (10 - i), -100.0]);
      particleFactoryTestObjects[i].acceleration = Vector.Zero(2);
      particleFactoryTestObjects[i].lastUpdatedTime = 0;
    }

    if (particleFactoryTestPhysicalSimulation.elapsedTime >= particleFactoryTestPhysicalSimulation.maxTime){
      particleFactoryTestPhysicalSimulation.initialize();  
      particleFactoryTestPhysicalSimulation.maxTime = 20000;  
      particleFactoryTestPhysicalSimulationPhysicalSimulation.elapsedTime = 0;
      particleFactoryTestPhysicalSimulationPhysicalSimulation.start();
    }
    else{
      particleFactoryTestPhysicalSimulation.elapsedTime = 0;
    }
  });

  particleFactoryTestPhysicalSimulation.start();

  return true;
}
</script>
